//
//  WYRedDataView.m
//  Boss
//
//  Created by admin on 2018/6/6.
//  Copyright © 2018年 admin. All rights reserved.
//

#import "WYRedDataView.h"
@interface WYRedDataView()<UIPickerViewDelegate,UIPickerViewDataSource>

@property (nonatomic,strong)UIPickerView *datePicker;
@property (nonatomic,strong)NSArray *dataArray;
@property (nonatomic,strong)NSString *value;
@end
@implementation WYRedDataView
-(instancetype)initWithArray:(NSArray *)array
{
    _dataArray = array;
    return [self init];
}


-(instancetype)init
{
    if (self = [super init]) {
        [self createSubViews];
    }
    return self;
}
-(void)createSubViews
{
    UIView *topView = [[UIView alloc]init];
    [self addSubview:topView];
    [topView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.right.left.mas_equalTo(0);
        make.height.mas_equalTo(44);
    }];
    topView.backgroundColor = [UIColor hexStringToColor:@"#f7f7f7" alpha:1.0];
    
    UILabel *centerLabel = [[UILabel alloc]init];
    [topView addSubview:centerLabel];
    [centerLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.mas_equalTo(topView);
    }];
    centerLabel.text = @"红包规则";
    
    UIButton *leftBtn = [[UIButton alloc]init];
    [topView addSubview:leftBtn];
    
    [leftBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.centerY.mas_equalTo(topView);
    }];
    
    [leftBtn setTitle:@"取消" forState:UIControlStateNormal];
    [leftBtn addTarget:self action:@selector(cancelBtnAction) forControlEvents:(UIControlEventTouchUpInside)];
    [leftBtn setTitleColor:[UIColor hexStringToColor:@"#333333" alpha:1.0] forState:(UIControlStateNormal)];
    
    
    UIButton *rightBtn = [[UIButton alloc]init];
    [topView addSubview:rightBtn];
    
    [rightBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-15);
        make.centerY.mas_equalTo(topView);
    }];
    [rightBtn setTitle:@"确认" forState:UIControlStateNormal];
    [rightBtn addTarget:self action:@selector(sureBtnAction) forControlEvents:UIControlEventTouchUpInside];
    [rightBtn setTitleColor:kColorMainColor forState:UIControlStateNormal];
    self.datePicker = [[UIPickerView alloc]init];
    [self addSubview:self.datePicker];
    [self.datePicker mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.mas_equalTo(0);
        make.top.mas_equalTo(44);
    }];
    self.datePicker.delegate = self;
    self.datePicker.dataSource  = self;
}
- (NSInteger)numberOfComponentsInPickerView:(nonnull UIPickerView *)pickerView {
    return 1;
}

- (NSInteger)pickerView:(nonnull UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
    return self.dataArray.count;
}

-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
    return self.dataArray[row];
}
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
    self.value = self.dataArray[row];
}

-(void)cancelBtnAction
{
    [self removeFromSuperview];
}
-(void)sureBtnAction
{
    NSLog(@"%@",self.value);
    [self removeFromSuperview];
    
    self.complete(self.value, nil);
    
    
    
}



@end
